﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LBCMS.EntityFrameWork.FrameModel;

namespace LBCMS.Controllers
{
    
    
    public class userApiController : Controller
    {
        Helper.JsonHelper.retDataSingle<B_Users> ret = new Helper.JsonHelper.retDataSingle<B_Users>();
        LBCMS.EntityFrameWork.BLLContext db = new EntityFrameWork.BLLContext();

        // GET: userApi
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult get()
        {
            string userGuid = Session["userGuid"].ToString();
            var user =  db.B_Users.FirstOrDefault(p => p.userGuid == userGuid);

            ret.success = true;
            ret.data = user;

            return Content(Helper.JsonHelper.toJson(ret));

            
        }

        public ActionResult eidt(B_Users user)
        {
            db.B_Users.Attach(user);
            db.Entry(user).State = System.Data.Entity.EntityState.Modified;
            db.SaveChangesAsync();
            ret.success = true;
            return Content(Helper.JsonHelper.toJson(ret));
        }

        public ActionResult delete(string userGuidList)
        {
            var user = userGuidList.Split(';');
            foreach (var item in user)
            {
                if (item != "")
                {
                    var data = new B_Users();
                    data.userGuid = item;
                    db.B_Users.Attach(data);
                    db.Entry(data).State = System.Data.Entity.EntityState.Modified;
                }
            }

            db.SaveChangesAsync();

            ret.success = true;

            return Content(Helper.JsonHelper.toJson(ret));
        }
    }
}